package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.UserBankModel
import com.baizan.daka.ui.contract.LoginContract
import com.baizan.daka.mvp.model.UserModel
import com.baizan.daka.mvp.model.bean.LoginInfoBean
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.ModifyMoneyPasswordContract
import com.baizan.daka.ui.contract.ModifyPasswordContract
import com.baizan.daka.util.Md5

class ModifyMoneyPasswordPresenter(val mView: ModifyMoneyPasswordContract.View) : BasePresenter(),
    ModifyMoneyPasswordContract.Presenter {

    private val bankModel: UserBankModel by lazy {
        UserBankModel()
    }

    override fun modifyPassword(password: String, newPassword: String) {
        mView.showLoadingDialog()
        bankModel.modifyPassword(password
                ,newPassword)
            .subscribe(object :CommonSubscriber<String>(compositeDisposable){
                override fun onCallNext(t: String?) {
                    mView.modifyPasswordSuccess()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

            })
    }

    override fun addPassword(password: String) {
        mView.showLoadingDialog()
        bankModel.addPassword(password)
            .subscribe(object :CommonSubscriber<String>(compositeDisposable){
                override fun onCallNext(t: String?) {
                    mView.addPasswordSuccess()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

            })
    }

    override fun getPassword() {
        mView.showLoadingDialog()
        bankModel.getPassword()
            .subscribe(object :CommonSubscriber<String>(compositeDisposable){
                override fun onCallNext(t: String?) {
                    mView.getPasswordSuccess(t!!)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

            })
    }


}

